<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>菜单--修改名称</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport"
              content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
        <link rel="stylesheet" href="/components/layuiadmin/layui/src/css/layui.css">
        <link href="/components/iconFonts/font-awesome/css/font-awesome.css?v=4.7.0" rel="stylesheet">


        <script src="/manage/js/app.js"></script>
    </head>
    <script>
        layui.config({
            base: '/components/iconFonts/module/'
        }).extend({
            iconHhysFa: 'iconHhys/iconHhysFa'
        });
    </script>
    <style>
        .layui-form-item .layui-input-inline {
            width: 360px;
        !important;
        }
    </style>
    <body>

        <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list"
             style="padding: 20px 30px 0 0;">
            <div id="terminalDiv" class="layui-form-item">
                <label class="layui-form-label">终端</label>
                <div id="terminal" class="layui-input-block">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div id="urlDiv" class="layui-form-item">
                <label class="layui-form-label">路由</label>
                <div class="layui-input-inline">
                    <input type="text" id="url" name="url" placeholder="请输入路由" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div id="twoUrlDiv" class="layui-form-item">
                <label class="layui-form-label">第二路由</label>
                <div class="layui-input-inline">
                    <input type="text" id="twoUrl" name="twoUrl" placeholder="非必填" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-inline">
                    <input type="text" id="sort" name="sort" lay-verify="required" placeholder="请输入排序" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">图标</label>
                <div class="layui-input-inline">
                    <input type="text" id="icon" name="icon" value="layui-icon-file-b" lay-verify="required" placeholder="请选择图标" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="" class="layui-form-label">选择图标：</label>
                <div class="layui-input-block">
                    <input type="text" id="iconHhysFa2" value="layui-icon-file-b" lay-filter="iconHhysFa2" class="hide">
                </div>
            </div>
            <div class="layui-form-item layui-hide">
                <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit"
                       value="确认添加">
                <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit"
                       value="确认编辑">
            </div>
        </div>
    </body>
    <script>
        layui.use(['iconHhysFa', 'form'], function () {
            init();
            formSubmit();
        });

        function init() {
            //判断
            if (parent.data.root === 1) {
                // 添加系统--屏蔽路由
                $("#urlDiv").attr("style", "display:none");
                $("#twoUrlDiv").attr("style", "display:none");
            } else if (parent.data.root === 2) {
                // 添加菜单--屏蔽路由, 屏蔽终端
                //  $("#terminalDiv").attr("style", "display:none");
                $("#urlDiv").attr("style", "display:none");
                $("#twoUrlDiv").attr("style", "display:none");
            } else if (parent.data.root === 3) {
                // 添加页面--路由设置为必填, 屏蔽终端
                // $("#terminalDiv").attr("style", "display:none");
                $("#url").attr("lay-verify", "required");
            }

            $("#terminal").html(Dict.getDictRadio(Enums.Admin.Terminal, "terminal", parent.data.terminal)); // 终端
            // 刷新,否则select可能不生效
            layui.form.render();

            // 回显父页面的值
            $("#name").val(parent.data.name);
            $("#icon").val(parent.data.icon);
            $("#iconHhysFa2").val(parent.data.icon);
            $("#url").val(parent.data.url);
            $("#twoUrl").val(parent.data.twoUrl);
            $("#sort").val(parent.data.sort);

            layui.iconHhysFa.render({
                // 选择器，推荐使用input
                elem: '#iconHhysFa2',
                // 数据类型：fontClass/awesome，推荐使用fontClass
                type: 'fontClass',
                // 是否开启搜索：true/false
                search: false,
                //url: '',
                url: './font-awesome/less/variables.less',
                // 是否开启分页
                page: false,
                // 每页显示数量，默认12
                limit: 12,
                // 点击回调
                click: function (data) {
                    $("#icon").val(data.icon);
                },
                // 渲染成功后的回调
                success: function (d) {
                    //console.log(d);
                }
            });
        }

        function formSubmit() {
            //监听提交
            layui.form.on('submit(layuiadmin-app-form-submit)', function (res) {
                let data = res.field;
                // 修改
                let result = Ajax.put(parent.menuUrl + "/" + parent.data.id, data);
                // 关闭弹层
                let index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
                parent.layer.msg(result.msg);
                // 重载页面 // parent.window.location.reload();
                WindowPos.onbeforeunload();  // 记录滚动条位置
                parent.xijiaRenderTable();
                WindowPos.onload();          // 还原滚动条位置
            });
        }
    </script>

</html>